<template>
  <div class="unit-box">
    <div class="child-box" v-if="store.childModel.children.length == 1">
      <div class="child-item">
        <div class="child-item-bgc">
          <buttonStyle :isActive="true" />
        </div>
        <div class="child-item-info">
          <t-avatar
            size="72px"
            :image="
              store.childModel.children[0].value
                ? $filters.getLinkUrl(store.childModel.children[0].value, '?imageView2/0/w/160/h/160/format/webp')
                : ImgUrlCancat + `/template/template5/templateDefult${store.styleInfo.colorType}.png`
            "
          >
          </t-avatar>
          <div class="info-right">
            <div class="info-right-parent">
              <span class="info-right-text1">{{ store.childModel.children[0].text }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="child-box2" v-else-if="store.childModel.children.length == 2">
      <div class="child-item" @click="setCruuent(index)" v-for="(item, index) in store.childModel.children" :key="item">
        <div class="child-item-bgc">
          <buttonStyle :isActive="current == index" />
        </div>
        <div class="child-item-info">
          <t-avatar
            size="72px"
            :image="
              item.value
                ? $filters.getLinkUrl(item.value, '?imageView2/0/w/160/h/160/format/webp')
                : ImgUrlCancat + `/template/template5/templateDefult${store.styleInfo.colorType}.png`
            "
          >
          </t-avatar>
          <div class="info-right">
            <div class="info-right-parent">
              <span class="info-right-text1">{{ item.text }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="child-box3" v-else>
      <div class="child-box3-left">
        <arrowLeft
          iconSize="50px"
          @click="addCruuent(1)"
          :color="colorList5[store.styleInfo.colorType - 1].fontColor"
        />
      </div>
      <div class="child-box3-center">
        <div class="child-box3-center-scroll" :style="{ transform: getScrollLeft }">
          <div
            class="scroll-item"
            @click="setCruuent(index)"
            v-for="(item, index) in store.childModel.children"
            :key="item"
          >
            <div
              :class="{
                'scroll-item-bgc-1': index == current - 1 || index == current + 1,
                'scroll-item-bgc-2': index !== current - 1 && index !== current + 1 && index !== current,
                'scroll-item-bgc-active': index == current,
              }"
            >
              <numberUnitBtn :isActive="current == index" />
            </div>
            <div
              class="scroll-item-info"
              :class="{
                'scroll-item-info-1': index == current - 1 || index == current + 1,
                'scroll-item-info-2': index !== current - 1 && index !== current + 1 && index !== current,
                'scroll-item-info-active': index == current,
              }"
            >
              <div
                class="avatar-box-parent"
                :class="{
                  'avatar-box-1': index == current - 1 || index == current + 1,
                  'avatar-box-2': index !== current - 1 && index !== current + 1 && index !== current,
                  'avatar-box-active': index == current,
                }"
              >
                <img
                  class="cover-box"
                  :class="{
                    'cover-box-1': index === current - 1 || index === current + 1,
                    'cover-box-active': index == current,
                  }"
                  :src="item.value"
                />
                <!-- <img v-else-if="index === current - 1 || index === current + 1" size="80px" :image="item.value">
               
                <img v-else size="72px" :image="item.value">  -->
                <div
                  class="avatar-box-flot"
                  :style="{ borderColor: colorList5[store.styleInfo.colorType - 1].fontColor }"
                ></div>
              </div>
              <div class="scroll-item-info-bottom">
                <span class="scroll-item-info-bottom-title2">{{ item.text }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="child-box3-right">
        <arrowRight
          @click="addCruuent(2)"
          iconSize="50px"
          :color="colorList5[store.styleInfo.colorType - 1].fontColor"
        />
      </div>
    </div>
    <div class="unit-exbit-title-box">
      <div
        :style="{ color: colorList5[store.styleInfo.colorType - 1].fontColor }"
        class="subTitle"
        v-if="store.childModel.children[current].subTitle"
      >
        ——{{ store.childModel.children[current].subTitle }}
      </div>
      <div class="unit-exbit-title-box-right-box" v-if="store.childModel.children[current].value">
        <img
          @click="lookCover"
          class="unit-exbit-title-box-right"
          :src="store.childModel.children[current].value"
          alt=""
          v-if="store.childModel.children[current].value"
        />
      </div>
      <div
        class="unit-exbit-title-box-left"
        :class="'unitChildChildExhibit-heard-remarks' + store.styleInfo.colorType"
        v-html="remarks"
      ></div>
      <t-image-viewer v-model:visible="visible" :images="[lookUrl]"> </t-image-viewer>
    </div>
  </div>
</template>

<script setup lang="ts">
// @ts-nocheck
import { ImgUrlCancat } from '@/utils/minxin';
import arrowLeft from '../../components/arrowLeft.vue';
import arrowRight from '../../components/arrowRight.vue';
import buttonStyle from './buttonStyle.vue';
import numberUnitBtn from './numberUnitBtn.vue';
import paginationPage from '../../components/paginationPage.vue';
import childInfo from './childInfo.vue';
import textMax from '../../components/textMax.vue';
import imageNull from '@/components/imageNull/index.vue';
import { getTextHtml, filterHTML, convertToPinyin } from '@/utils/minxin';
import { exhibitShowpiece } from '@/api/templates/templates';
import { colorList5 } from '../../../data';
import titles from '../../components/title.vue';
import { urls } from '@/utils/request/upload';
import { ref, reactive, computed, watch } from 'vue';
import { MessagePlugin } from 'tdesign-vue-next';
import { useProjectStore } from '@/store';
import { moduleShowpieces } from '@/api/exhibit/exhibit';
import { storeToRefs } from 'pinia';
import UnitImageNull from '@/components/unitImageNull/unitImageNull.vue';

const props = defineProps({
  modelValue: {
    type: Number,
  },
});
const emit = defineEmits(['update:modelValue']);
const store = useProjectStore();
const { childModel } = storeToRefs(store);
const current = ref(0);
const remarks = ref('');
const exbitMarsk = ref('');
const loading = ref(false);
const list = ref([]);
const lookUrl = ref('');
const visible = ref(false);
const getEnglish = (e: string) => {
  let str: string = '';
  if (e.length > 4) {
    let strS = e.slice(0, 4);
    str = convertToPinyin(strS);
  } else {
    str = convertToPinyin(e);
  }
  return str;
};
const setCruuent = (types: number) => {
  current.value = types;
  emit('update:modelValue', types);
};
const lookCover = () => {
  lookUrl.value = store.childModel.children[current.value].value;
  visible.value = true;
};
const getScrollLeft = computed(() => {
  // 190 * current
  let num = 0;
  if (current.value === 0) {
    num = 0;
  } else if (current.value === 1) {
    num = 212;
  } else {
    num = 212 + 194 * (current.value - 1);
  }
  return `translateX(-${num}px)`;
});
const addCruuent = (type: number) => {
  if (type === 1) {
    if (current.value == 0) {
      current.value = store.childModel.children.length - 1;
    } else {
      current.value = current.value - 1;
    }
  } else {
    if (current.value == store.childModel.children.length - 1) {
      current.value = 0;
    } else {
      current.value = current.value + 1;
    }
  }
  emit('update:modelValue', current.value);
};
remarks.value = getTextHtml(store.childModel.children[current.value]?.remarks);

watch(
  childModel,
  () => {
    remarks.value = getTextHtml(store.childModel.children[current.value]?.remarks);
  },
  { deep: true },
);
watch(
  () => props.modelValue,
  () => {
    current.value = props.modelValue;
    remarks.value = getTextHtml(store.childModel.children[current.value]?.remarks);
  },
  { deep: true },
);
</script>

<style lang="less" scoped>
@import '../../index.less';
.unit-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  min-width: 1180px;
  margin-top: 20px;
  padding-bottom: 150px;
}
.unit-exbit-title-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 1180px;
  margin: 0 auto;
}
.unit-exbit-title-box-left {
  display: flex;
  flex-direction: column;
  width: 100%;

  margin-top: 50px;
  :deep(span) {
    display: inline-block;
    font-size: 16px;
    font-family: PingFangSC, PingFang SC;

    color: #333333;
    line-height: 32px;
    text-align: justify;
    text-indent: 2em;
    margin-bottom: 20px;
  }
  :deep(span:last-of-type) {
    margin-bottom: 0px !important;
  }
}
.unitChildChildExhibit-heard-remarks1 {
  :deep(span) {
    color: #e9d5b0;
  }
}
.unitChildChildExhibit-heard-remarks2 {
  :deep(span) {
    color: #cbb995;
  }
}
.unitChildChildExhibit-heard-remarks3 {
  :deep(span) {
    color: #e9d5b0;
  }
}
.unit-exbit-title-box-right-box {
  position: relative;
  width: 100%;
  margin-top: 50px;
  img {
    cursor: pointer;
    width: 100%;
    height: auto !important;
    object-fit: contain !important;
  }
}
.unit-exbit-title-box-right,
.UnitImageNull {
  width: 100%;
  height: auto;
  object-fit: contain;
}
.child-box {
  display: flex;
  justify-content: center;
  width: 1180px;
}
.child-box2 {
  display: flex;
  justify-content: space-around;
  width: 1180px;
}
.child-item {
  cursor: pointer;
  position: relative;
  width: 544px;
  height: 152px;
}
.child-item-bgc {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
.child-item-info {
  position: relative;
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 40px 130px;
}
.btm-item-info-img {
  width: 29px;
  height: 29px;
}
.t-avatar {
  flex-shrink: 0;
}
.info-right {
  display: flex;
  flex-direction: column;
  // flex: 1;
  margin-left: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.info-right-parent {
  height: 100%;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.info-right-text1 {
  font-size: 18px;
  font-family: SourceHanSerifCN-Bold, SourceHanSerifCN;
  color: #333333;
  line-height: 24px;

  border-bottom: 1px solid #333333;
}
.info-right-text2 {
  width: 100%;
  height: 1px;
  background: #333333;
  border-radius: 0px;
  margin: 2px 0;
}
.info-right-text3 {
  font-size: 10px;
  font-family: SourceHanSerifCN-Bold, SourceHanSerifCN;
  color: #333333;
  line-height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.child-box3 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 1180px;
  height: 356px;
}
.child-box3-left {
  width: 60px;
  height: 60px;
}
.child-box3-center {
  flex: 1;
  margin: 0 24px;
  overflow: hidden;
}
.child-box3-center-scroll {
  display: flex;
  align-items: center;
  height: 356px;
  transition: all 0.5s;
  padding-left: 374px;
}
.child-box3-right {
  width: 60px;
  height: 60px;
}
.scroll-item {
  cursor: pointer;
  position: relative;
  margin-left: 32px;
}
.scroll-item-bgc-1 {
  position: absolute;
  top: 0;
  left: 0;
  width: 180px;
  height: 320px;
  opacity: 0.5;
}
.scroll-item-bgc-2 {
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0.25;
  width: 162px;
  height: 288px;
}
.scroll-item-bgc-active {
  position: absolute;
  top: 0;
  left: 0;
  width: 200px;
  height: 356px;
}
.scroll-item-info-1 {
  display: flex;
  flex-direction: column;
  align-items: center;

  width: 180px;
  height: 320px;
  padding: 18px;
  .scroll-item-info-bottom {
    position: relative;
    z-index: 20;
    display: flex;
    justify-content: center;
    // height: 94px;
    height: 180px;
    padding: 0 10px;
    margin-top: 20px;
    width: 100%;
    overflow: hidden;
  }
  .scroll-item-info-bottom-title1 {
    font-size: 10px;
    font-family: SourceHanSerifCN-Bold, SourceHanSerifCN;
    color: rgba(51, 51, 51, 0.5);
    line-height: 16px;
    height: 100%;
    writing-mode: vertical-lr; /* 控制文字从上至下排列，可选值还有 vertical-rl */
    text-orientation: upright; /* 控制文字正立排列 */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .scroll-item-info-bottom-title2 {
    font-size: 17px;
    color: #333333;
    line-height: 29px;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    // text-decoration: underline;
    // text-decoration-thickness: 1px;
    font-family: SourceHanSerifCN-Bold, SourceHanSerifCN;
    text-overflow: ellipsis;
    writing-mode: vertical-lr; /* 控制文字从上至下排列，可选值还有 vertical-rl */
    text-orientation: upright; /* 控制文字正立排列 */
  }
}
.scroll-item-info-bottom-title2 {
  font-family: SourceHanSerifCN-Bold, SourceHanSerifCN;
  // text-underline-offset: 4px;
  letter-spacing: 3px;
}
.scroll-item-info-2 {
  display: flex;
  flex-direction: column;
  align-items: center;

  width: 162px;
  height: 288px;
  padding: 16px;
  .scroll-item-info-bottom {
    position: relative;
    z-index: 20;
    display: flex;
    justify-content: center;
    height: 200px;
    padding: 0 10px;
    margin-top: 20px;
    width: 100%;
    overflow: hidden;
  }
  .scroll-item-info-bottom-title1 {
    font-size: 10px;
    font-family: SourceHanSerifCN-Bold, SourceHanSerifCN;
    color: rgba(51, 51, 51, 0.5);
    line-height: 16px;
    height: 100%;
    writing-mode: vertical-lr; /* 控制文字从上至下排列，可选值还有 vertical-rl */
    text-orientation: upright; /* 控制文字正立排列 */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .scroll-item-info-bottom-title2 {
    font-size: 18px;
    font-family: SourceHanSerifCN-Bold, SourceHanSerifCN;
    color: #333333;
    line-height: 26px;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    // text-decoration: underline;
    // text-decoration-thickness: 1px;
    text-overflow: ellipsis;
    writing-mode: vertical-lr; /* 控制文字从上至下排列，可选值还有 vertical-rl */
    text-orientation: upright; /* 控制文字正立排列 */
  }
}
.scroll-item-info-active {
  display: flex;
  flex-direction: column;
  align-items: center;

  width: 200px;
  height: 356px;
  padding: 20px;
  .scroll-item-info-bottom {
    position: relative;
    z-index: 20;
    display: flex;
    justify-content: center;
    height: 200px;
    padding: 0 10px;
    margin-top: 20px;
    width: 100%;
    overflow: hidden;
  }
  .scroll-item-info-bottom-title1 {
    font-size: 10px;
    font-family: SourceHanSerifCN-Bold, SourceHanSerifCN;

    color: rgba(51, 51, 51, 0.5);
    line-height: 16px;
    height: 100%;
    writing-mode: vertical-lr; /* 控制文字从上至下排列，可选值还有 vertical-rl */
    text-orientation: upright; /* 控制文字正立排列 */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .scroll-item-info-bottom-title2 {
    font-size: 19px;

    color: #333333;
    line-height: 31px;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    // text-decoration: underline;
    text-decoration-thickness: 1px;
    text-overflow: ellipsis;
    writing-mode: vertical-lr; /* 控制文字从上至下排列，可选值还有 vertical-rl */
    text-orientation: upright; /* 控制文字正立排列 */
  }
}

.avatar-box-1 {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 80px;
  height: 80px;
  .avatar-box-flot {
    position: absolute;
    top: 4px;
    left: 4px;
    border-radius: 50%;
    width: 72px;
    height: 72px;
    box-shadow: 0px 0px 4px 0px rgba(151, 173, 177, 0.5);
    border: 1px solid #cbb995;
  }
}
.avatar-box-2 {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 72px;
  height: 72px;
  .avatar-box-flot {
    position: absolute;
    top: 4px;
    left: 4px;
    border-radius: 50%;
    width: 64px;
    height: 64px;
    box-shadow: 0px 0px 4px 0px rgba(151, 173, 177, 0.5);
    border: 1px solid #cbb995;
  }
}

.avatar-box-parent {
  margin-top: 16px;
}
.avatar-box-active {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 88px;
  height: 88px;
  .avatar-box-flot {
    position: absolute;
    top: 4px;
    left: 4px;
    border-radius: 50%;
    width: 80px;
    height: 80px;
    box-shadow: 0px 0px 4px 0px rgba(151, 173, 177, 0.5);
    border: 1px solid #cbb995;
  }
}
.subTitle {
  margin-top: 18px;
}
.cover-box {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
}
.cover-box-1 {
  width: 80px;
  height: 80px;
}
.cover-box-active {
  width: 88px;
  height: 88px;
}
</style>
